package com.company.OfferGuide;

public class 二叉搜索树与双向链表02 {

    Node head,pre,tail;

    public Node treeToDoublyList(Node root){
        if (root == null) return null;
        process(root);
        head.left = tail;
        tail.right = head;

        return head;
    }

    public void process(Node node) {
        if (node == null) return;

        process(node.left);

        node.left = pre;
        if (pre == null) {
            head = node;
        } else {
            pre.right = node;
        }
        pre = node;
        tail = node;
        process(node.right);
    }
}
